package framework.aop.aspect;

import framework.aop.intercept.InchMethodInterceptor;
import framework.aop.intercept.InchMethodInvocation;

import java.lang.reflect.Method;

/**
 * class not finished !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 */
public class InchMethodAroundAdvice extends InchAbstractAspectAdvice implements InchAdvice, InchMethodInterceptor {
    private InchJoinPoint joinPoint;

    public InchMethodAroundAdvice(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(InchMethodInvocation methodInvocation) throws Throwable {

        before(methodInvocation.getMethod(),methodInvocation.getArguments(),methodInvocation.getThis());
        Object value = methodInvocation.proceed();
        after(methodInvocation.getMethod(),methodInvocation.getArguments(),methodInvocation.getThis());
        return value;
    }

    private void before(Method method, Object[] args, Object target) throws Throwable{
        invokeAdviceMethod(this.joinPoint,null,null);
    }
    private void after(Method method,Object[] args,Object target) throws Throwable {
        invokeAdviceMethod(this.joinPoint,null,null );
    }
}
